<?php

require_once './core/tools.php';

if (isset($_POST["type"]) && isset($_POST["id"])){

	switch ($_POST["type"]){
		case "client":
			$query0 = "DELETE versions_swf.* FROM versions_client, versions_projet, versions_swf WHERE versions_client.id_client = '".$_POST["id"]."' AND versions_client.id_client=versions_projet.id_client AND versions_projet.id_projet = versions_swf.id_projet";
			$result = executeSQL($query0);
			if (!$result){
				die ('{"error":1, "message":"MysqlError :'.addslashes(mysql_error()).'"}' );
			}
			
			$query1 = "DELETE versions_projet.* FROM versions_client, versions_projet WHERE versions_client.id_client = '".$_POST["id"]."' AND versions_client.id_client=versions_projet.id_client";
			$result = executeSQL($query1);
			if (!$result){
				die ('{"error":1, "message":"MysqlError :'.addslashes(mysql_error()).'"}' );
			}
			
			$query2 = "DELETE FROM versions_client WHERE versions_client.id_client = '".$_POST["id"]."'";
			$result = executeSQL($query2);
			if (!$result){
				die ('{"error":1, "message":"MysqlError :'.addslashes(mysql_error()).'"}' );
			}
			break;
		case "projet":
			$query0 = "DELETE versions_swf.* FROM versions_projet, versions_swf WHERE versions_projet.id_projet = '".$_POST["id"]."' AND versions_projet.id_projet = versions_swf.id_projet";
			$result = executeSQL($query0);
			if (!$result){
				die ('{"error":1, "message":"MysqlError :'.addslashes(mysql_error()).'"}' );
			}
			
			$query1 = "DELETE FROM versions_projet WHERE versions_projet.id_projet = '".$_POST["id"]."'";
			$result = executeSQL($query1);
			if (!$result){
				die ('{"error":1, "message":"MysqlError :'.addslashes(mysql_error()).'"}' );
			}
			
			break;
		case "swf":
			$query0 = "DELETE FROM versions_swf WHERE id_swf='".$_POST["id"]."'";
			$result = executeSQL($query0);
			if (!$result){
				die ('{"error":1, "message":"MysqlError :'.addslashes(mysql_error()).'"}' );
			}
			break;
	}

	echo '{"error":0, "message":"OK"}';
}
else {
	echo '{"error":2, "message":"missing parameters"}';
}


?>


